testsuite: Make creating the output dir not racy
authorBenjamin Otte <otte@redhat.com>
Sun, 9 Jun 2019 19:49:44 +0000 (21:49 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 9 Jun 2019 21:17:10 +0000 (23:17 +0200)
Fixes #1942

testsuite/gsk/compare-render.c
testsuite/reftests/gtk-reftest.c

index d15416c88a86e5947505742915427754f7ef8b49..a0e68a37cd772f973a92d8646de40c56ed47370d 100644 (file)
@@ -11,6 +11,7 @@ get_output_dir (void)
 {
   static const char *output_dir = NULL;
   GError *error = NULL;
+  GFile *file;
 
   if (output_dir)
     return output_dir;
@@ -26,21 +27,26 @@ get_output_dir (void)
       output_dir = g_get_tmp_dir ();
     }
 
-  if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
+  /* Just try to create the output directory.
+   * If it already exists, that's exactly what we wanted to check,
+   * so we can happily skip that error.
+   */
+  file = g_file_new_for_path (output_dir);
+  if (!g_file_make_directory_with_parents (file, NULL, &error))
     {
-      GFile *file;
+      g_object_unref (file);
 
-      file = g_file_new_for_path (output_dir);
-      if (!g_file_make_directory_with_parents (file, NULL, &error))
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
         {
           g_error ("Failed to create output dir: %s", error->message);
           g_error_free (error);
           return NULL;
         }
-
-      g_object_unref (file);
+      g_error_free (error);
     }
 
+  g_object_unref (file);
+
   return output_dir;
 }
 
index b0fb5741f62c99e6734ec4afdab87424e2aa0912..f54244db3eec2d44fd1bad9dd3f1ef012f9171ea 100644 (file)
@@ -95,7 +95,21 @@ get_output_dir (GError **error)
 
   if (arg_output_dir)
     {
-      GFile *file = g_file_new_for_commandline_arg (arg_output_dir);
+      GError *err = NULL;
+      GFile *file;
+
+      file = g_file_new_for_commandline_arg (arg_output_dir);
+      if (!g_file_make_directory_with_parents (file, NULL, &err))
+        {
+          if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_EXISTS))
+            {
+              g_propagate_error (error, err);
+              g_object_unref (file);
+              return NULL;
+            }
+          g_clear_error (&err);
+        }
+
       output_dir = g_file_get_path (file);
       g_object_unref (file);
     }
@@ -104,17 +118,6 @@ get_output_dir (GError **error)
       output_dir = g_get_tmp_dir ();
     }
 
-  if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
-    {
-      GFile *file;
-
-      file = g_file_new_for_path (output_dir);
-      if (!g_file_make_directory_with_parents (file, NULL, error))
-        return NULL;
-
-      g_object_unref (file);
-    }
-
   return output_dir;
 }